<?php

/**
 * XHTML_Style, xhtml_lib
 * 
 * This file contains the source code for the XHTML_Style class.
 * @author Fernando Jimenez Mocobono <fjmcool@gmail.com>
 * @version 0.1
 * @package xhtml_lib
 */

include_once "XHTML__Misc_Inline.php";

/**
 * The XHTML_Style class is a handler for the style xhtml-strict tag as a part
 * of a xhtml-strict php-handler implementation.
 */
class XHTML_Script implements XHTML__Misc_Inline {
    
    // xhtml attributes
    
    /**
     * Unique identifier for the xhtml-style-tag.
     * 
     * @var string
     */
    protected $id;
    
    /**
     * Character encoding of the target URI. Default value is "ISO-8859-1"
     *
     * @var string
     */
    protected $charSet;
    
    /**
     * Content-type.
     *
     * @var string
     */
    protected $type;
    
    /**
     * URI of a file that contains the script (instead of inserting the script 
     * into your HTML document, you can refer to a file that contains the 
     * script).
     *
     * @var string
     */
    protected $src;
    
    /**
     * Indicates that the script is not going to generate any document content.
     *  The browser can continue parsing and drawing the page.
     *
     * @var boolean
     */
    protected $defer;
    

    //inner elements
    
    /**
     * Script definition text.
     * 
     * @var string
     */
    protected $text;
    
    
    // Methods
    
    /**
     * Constructs a XHTML_Script object with its required type.
     */
    function __construct($type)
    {
        $this->type = $type;
        $this->defer = false;
    }
    
    /**
     * Sets the unique identifier.
     *
     * @param string $id
     */
    function setId($id)
    {
        $this->id = $id;
    }
    
    /**
     * Gets the unique identifier.
     *
     * @return string
     */
    function getId()
    {
        return $this->id;
    }
    
    /**
     * Sets the character encoding of the target URI.
     *
     * @param string $charSet
     */
    function setCharSet($charSet)
    {
        $this->charSet = $charSet;
    }
    
    /**
     * Gets the character encoding of the target URI.
     *
     * @return string
     */
    function getCharSet()
    {
        return $this->charSet;
    }
    
    /**
     * Sets the content-type.
     *
     * @param string $type
     */
    function setType($type)
    {
        $this->type = $type;
    }
    
    /**
     * Gets the content-type.
     *
     * @return string
     */
    function getType()
    {
        return $this->type;
    }
    
    /**
     * Sets the URI of a file that contains the script (instead of inserting 
     * the script into your HTML document, you can refer to a file that 
     * contains the script).
     *
     * @param string $src
     */
    function setSrc($src)
    {
        $this->src = $src;
    }
    
    /**
     * Gets the URI of a file that contains the script (instead of inserting 
     * the script into your HTML document, you can refer to a file that 
     * contains the script).
     *
     * @return string
     */
    function getSrc()
    {
        return $this->src;
    }
    
    /**
     * Indicates if the script is not going to generate any document content.
     *  The browser can continue parsing and drawing the page.
     * 
     * @param boolean $defer
     */
    function setDefer($defer)
    {
        $this->defer = $defer;
    }
    
    /**
     * Indicates if the script is not going to generate any document content.
     *  The browser can continue parsing and drawing the page.
     * 
     * @return boolean
     */
    function isDefer()
    {
        return $this->defer;
    }
    
    /**
     * Sets the script definition text.
     * 
     * @param string
     */
    function setText($text)
    {
        $this->text = $text;
    }
    
    /**
     * Gets the script definition text.
     *
     * @return string
     */
    function getText()
    {
        return $this->text;
    }
    
    // Overriding the toString method for a proper implementation.
    
    /**
     * Returns the string representation for echoing the class atributes.
     *
     * @return string
     */
    function toString()
    {
        $auxString = "<script ";
        
        /*
         * Additions of the script own attributes to the return string.
         */
        if (isset($this->id)) {
            $auxString = $auxString."id=\"".$this->id."\" ";
        }
        
        
        if (isset($this->charSet)) {
            $auxString = $auxString."charset=\"".$this->charSet."\" ";
        }
        
        $auxString = $auxString."type=\"".$this->type."\" ";
        
        if (isset($this->src)) {
            $auxString = $auxString."src=\"".$this->src."\" ";
        }
        
        if ($this->defer) {
            $auxString = $auxString."defer=\"defer\" ";
        }
        
        // DO NOT DELETE THE FOLLOWING LINE.
        // xml:space is a fixed attribute.
        $auxString = $auxString."xml:space=\"preserve\" >\n";
        
        /*
         * Additions of the inner elements of the script element to the return 
         * string.
         */
        if (isset($this->text)) {
        	$auxString = $auxString.$this->text."\n";
        }
        
        $auxString = $auxString."</script>\n";
        
        return $auxString;
    }
    
}

?>